package cn.wolfcode.wms.web.controller;

import cn.wolfcode.wms.domain.Orderbill;
import cn.wolfcode.wms.qo.OrederbillQuery;
import cn.wolfcode.wms.qo.QueryObject;
import cn.wolfcode.wms.service.IOrderbillService;
import cn.wolfcode.wms.service.ISupplierService;
import cn.wolfcode.wms.util.JSONResult;
import cn.wolfcode.wms.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("orderbill")
public class OrderbillController {
    @Autowired
    private IOrderbillService orderbillService;
    @Autowired
    private ISupplierService supplierService;
    @RequestMapping("list")
    public String list(Model model, @ModelAttribute("qo")OrederbillQuery qo){

        PageResult result = orderbillService.queryForList(qo);

        model.addAttribute("result",result);
        //供应商
        model.addAttribute("suppliers",supplierService.selectall());
        return "orderbill/list";
    }

    @RequestMapping("input")
    public String input(Model model,Long id){
        if (id != null) {
            Orderbill entity = orderbillService.get(id);
            System.out.println(entity);
            model.addAttribute("entity",entity);
        }
        //供应商
        model.addAttribute("suppliers",supplierService.selectall());
        return "orderbill/input";
    }
    //查看视图
    @RequestMapping("listView")
    public String listView(Model model,Long id){
        if (id != null) {
            Orderbill entity = orderbillService.get(id);

            model.addAttribute("entity",entity);
        }
        //供应商

        return "orderbill/listView";
    }
    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Orderbill entity){
        //在SpringMvc中对集合传值,需要索引
       orderbillService.saveOrUpdate(entity);
        return new JSONResult();
    }
    @ResponseBody
    @RequestMapping("delete")
    public Object delete(Long id){

       orderbillService.delete(id);
        JSONResult json = new JSONResult();
        return json;
    }

    @ResponseBody
    @RequestMapping("audit")
    public Object audit(Long id){

        orderbillService.audit(id);
        JSONResult json = new JSONResult();
        return json;
    }
}
